package sys.cloud.demo.controller;

import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 测试读取配置服务中心的配置
 * Created by shiyusen on 2017/3/11.
 */
@RefreshScope
@RestController
public class TestRemoteConfigController {
    //    访问配置服务器提供的配置信息
//    @Value("${mysqldb.datasource.url}")
//    private String from;
//
//    @ResponseBody
//    @RequestMapping("/from")
//    public String from() {
//        return this.from;
//    }

    @RequestMapping("/get")
    public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
//        InputStream inputStream=request.getServletContext().getResourceAsStream("b.properties");
        InputStream inputStream=TestRemoteConfigController.class.getClassLoader().getResourceAsStream("b.properties");
        byte[] data=new byte[inputStream.available()];
        System.out.println("----------------------------");
        inputStream.read(data);
        inputStream.close();
        OutputStream outputStream=response.getOutputStream();
        outputStream.write(data);
        outputStream.flush();
        outputStream.close();
    }

}
